package com.wnxy.web.servlet;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wnxy.entity.Employee;
import com.wnxy.service.impl.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    private static final long serialVersionUID = 12L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.调用业务逻辑层查询员工对象
        EmployeeServiceImpl esi =new EmployeeServiceImpl();
        List<Employee> allemp = esi.findAllemp();
        PageHelper.startPage(1, 5);
//        System.out.println(allemp);
        if (allemp!=null){
            PageInfo<Employee> info = new PageInfo<>(allemp);
            System.out.println(info);
            req.setAttribute("info",info);
        }
        //2. 转发到index.jsp
        req.getRequestDispatcher("/index.jsp").forward(req,resp);

    }
}
